
<template>
  <!-- ["
  id"
   "org_city_name"
   "dst_city_name"
   "airline_name"
   "airport_tax_audlet"
   "airport_tax_child"
   "base_price"
   "dst_airport"
   "dst_airport_name"
   "dst_airport_quay"
   "flight_no"
   "org_airport"
   "org_airport_name"
   "org_airport_quay"
   "plane_name"
   "plane_size"
   "seat_infos"
   "airorders"
   "flights"
   "arr_date"
   "dep_date"
   "arr_datetime"
   "arr_time"
   "dep_datetime"
   "dep_time"
   "created_at"
   "updated_at"] 
   flightsitem
   -->

  <div class="flights_item">
    <div
      class="flights_item_title"
      @click="show=!show"
    >
      <span class="flights_item_time">{{duration}} {{flightsitem.plane_size}} </span>
      <div class="flights_item_inner flights_item_name">
        {{flightsitem.airline_name}}
        {{flightsitem.flight_no}}
      </div>
      <div class="flights_item_inner flights_item_airport">
        <div class="flights_item_airport_row1">{{flightsitem.dep_time}}</div>
        <div class="flights_item_airport_row2">{{flightsitem.org_airport_name}} {{flightsitem.org_airport_quay}} </div>
      </div>
      <div class="flights_item_inner flights_item_airport">
        <div class="flights_item_airport_row1">{{flightsitem.arr_time}}</div>
        <div class="flights_item_airport_row2">{{flightsitem.dst_airport_name}} {{flightsitem.dst_airport_quay}}</div>
      </div>
      <div class="flights_item_inner flights_item_price">
        <div>￥ <span>{{flightsitem.base_price}}</span> 起</div>
      </div>
    </div>
    <div
      class="flights_item_content"
      v-show="show"
    >

      <span class="low_price">低价推荐</span>

      <div
        v-for="item in flightsitem.seat_infos"
        :key="item.index"
        class="flights_item_content_row"
      >
        <div class="flights_item_content_col1">
          <span>{{item.group_name}}</span> | {{item.supplierName}}
        </div>
        <div class="flights_item_content_col2">￥{{item.org_settle_price}} </div>
        <div class="flights_item_content_col3">
          <el-button
            type="warning"
            class="choose_btn"
            @click="goOrderPage(item)"
          >选定</el-button>
          <span>剩余:{{item.discount}}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["flightsitem"],
  data() {
    return {
      show: false,
    };
  },
  computed: {
    duration() {
      // 时间戳计算方式

      // 起飞时间
      // this.flightsitem.dep_datetime    "2020-08-31 11:25:00"
      // 到达时间
      // this.flightsitem.arr_datetime    "2020-08-31 08:00:00"

      //
      const depTimes = +new Date(this.flightsitem.dep_datetime); // 出发 时间戳
      const arrTimes = +new Date(this.flightsitem.arr_datetime); // 到达  时间戳

      let diffTimes = arrTimes - depTimes; // 两个时间戳

      // 只是针对 错误的后台 额外加的一天 真实情况下 不存在的!!!
      diffTimes = diffTimes < 0 ? diffTimes + 24 * 60 * 60 * 1000 : diffTimes;

      // const day = parseInt(diffTimes / 1000 / 60 / 60 / 24);

      // 相差 小时数
      const hour = parseInt(diffTimes / 1000 / 60 / 60);

      // 分钟数
      const minutes = diffTimes / 1000 / 60 - hour * 60;

      return `${hour}时${minutes}分钟`;
    },
  },
  methods: {
    goOrderPage(item) {
      const { id } = this.flightsitem;
      const { seat_xid } = item;
      this.$router.push({path:"/air/order",query:{id,seat_xid}});
    },
  },
};
</script>

<style lang="less" scoped  >
.flights_item {
  border: 1px solid #ccc;
  margin-bottom: 15px;
  .flights_item_title {
    display: flex;
    height: 75px;
    position: relative;
    .flights_item_time {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 13px;
      color: #666;
      padding-bottom: 15px;
      border-bottom: 1px solid #ccc;
    }
    .flights_item_inner {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    .flights_item_inner.flights_item_name {
      font-size: 14px;
    }

    .flights_item_inner.flights_item_airport {
      .flights_item_airport_row1 {
        font-size: 22px;
      }

      .flights_item_airport_row2 {
        font-size: 12px;
        color: #666;
      }
    }

    .flights_item_inner.flights_item_price {
      font-size: 16px;
      span {
        font-size: 20px;
        color: #e6a23c;
      }
    }
  }

  .flights_item_content {
    background-color: #f6f6f6;
    padding-left: 140px;
    position: relative;
    .low_price {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      left: 20px;
      font-size: 14px;
      color: #000;
    }
    .flights_item_content_row {
      border-bottom: 1px solid #ccc;
      height: 70px;
      display: flex;
      align-items: center;
      &:last-child {
        border-bottom: none;
      }
      .flights_item_content_col1 {
        font-size: 12px;
        flex: 4;
        span {
          color: green;
        }
      }

      .flights_item_content_col2 {
        flex: 1;
        color: #e6a23c;
        font-size: 18px;
      }

      .flights_item_content_col3 {
        height: 100%;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
        padding-right: 15px;
        .choose_btn {
          width: 70px;
          height: 27px;
          padding: 0;
          margin: 0;
          line-height: 1;
          display: flex;
          justify-content: center;
          align-items: center;
        }
        span {
          font-size: 12px;
          color: #666;
        }
      }
    }
  }
}
</style>